<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <ul>
        <!-- v-for和v-if不要一起使用 -->
        <!-- v-for的优先级更高, 所以会先将所有的元素全部都渲染 -->

        <!-- 1. 当条件和item有关的时候, 要使用计算属性先进行过滤 -->
        <li v-for="item in oddList" :key="item">{{ item }}</li>
      </ul>

      <!-- 2. 当条件和item无关的时候, 要将v-if提到父元素的上面 -->
      <ul v-if="show">
        <li v-for="item in list" :key="item">{{ item }}</li>
      </ul>
    </div>

    <script src="../Vue.js"></script>
    <script>
      new Vue({
        el: "#app",
        data: {
          list: [1, 2, 3, 4, 5, 6, 7, 8, 9],
          show: true,
        },
        computed: {
          oddList() {
            return this.list.filter((item) => item % 2);
          },
        },
      });
    </script>
  </body>
</html>
